<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ActiveForm;
use backend\models\Permission;
use backend\models\UserPermission;
/* @var $this yii\web\View */
/* @var $model backend\models\User */

$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-view">

    <p>
        <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
        <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
                'method' => 'post',
            ],
        ]) ?>
    </p>
    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
            'username',
            'group_id',
            //'password_hash',
            //'password_reset_token',
            'email:email',
            
            [
                'attribute' => 'status',
                'value' => $model->statusLabel,
            ],
            'created_at:datetime',
            'updated_at:datetime',
        ],
    ]) ?>

</div>

<div class="user-form">    
  
     <?php 
        $form = ActiveForm::begin([
            'options'=>['class' => 'form-horizontal', 'enctype'=>'multipart/form-data']
        ]); 
    ?> 
    <div class="canine">
        <ul class="all-checkbox">
            <li><input type="checkbox" id="all" name="check-all" /> <b> Chọn tất quyền trong hệ thống</b> </li>
            <?php 
                $premissions = Permission::loadArrayAllPermission();
                $user_permission = UserPermission::getArrayOfUser($model->id);
                $m=1;
                if(count($premissions)>0){
                    foreach ($premissions as $pre){?>
            <li class="parent-list col-lg-4">
                <input type="checkbox" value="<?=$pre['id']?>" name="checkbox[]" class="canine parent" <?= (isset($user_permission) && in_array($pre['id'], $user_permission))?' checked="checked" ':''; ?> /> <b> <?=$pre['name']?> </b> 
                <ul>
                    <?php foreach($pre['CHID'] as $c){?>
                    <li><input type="checkbox" name="checkbox[]" class="canine" value="<?=$c['id']?>" <?= (isset($user_permission) && in_array($c['id'], $user_permission))?' checked="checked" ':''; ?> /> <?=$c['name']?> </li>
                    <?php }?>
                </ul>
            </li>       
            <?php   
                        if($m%3==0){ 	    		
                            echo "<div class='clear-all'></div>"; 
                        }    
                        $m++;

                    }
                }
             
            ?>
          
           
	</ul>     
    </div>  
    <div class='clear-all'></div>
   <div class="form-group buttom-update-permission">                
        <button class="btn btn-success" type="submit">Create</button>
   </div>
    <?php ActiveForm::end(); ?>
</div>
